﻿/*=======================================================================================
	TASK 6:                                                   {Using Classes and Objects}
	You are given a sequence of positive integer values written into a string,
    separated by spaces. Write a function that reads these values from given
    string and calculates their sum.
    Example: string = "43 68 9 23 318" => result = 461
=======================================================================================*/

using System;

namespace _06.SumOfSeparatedBySpacesString
{
    class SumOfSeparatedBySpacesString
    {
        static void Main()
        {
            string str = "43 68 9 23, 318";
            Console.WriteLine(str);
            int sum = SumSeparator(str);
            Console.WriteLine(sum);
        }

        static int SumSeparator(string str)
        {
            int sum = 0;

            char[] charSeparators = new char[] { ' ', ',', '-', '/' };
            string[] numbers = str.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            
            foreach (var num in numbers)
            {
                sum = sum + int.Parse(num);
            }
            return sum;
        }
    }
}
